import React, { Component } from 'react';
import { connect } from 'dva';
import { TableC } from '../../../../comps';

@connect(({ nonstandardReportM, loading }) => ({
  nonstandardReportM,
  loading: loading.effects['nonstandardReportM/getTableDetail'],
}))
export default class CashFlowTable extends Component {
  state = {
    dataSource: undefined,
    columns: [
      {
        title: '日期',
        key: 'date',
        width: 150,
        type: 'date',
      },
      {
        title: '资产代码',
        key: 'tradingCode',
      },
      {
        title: '资产名称',
        key: 'tradingName',
      },
      {
        title: '流入金额（元）',
        key: 'cashFlowIncome',
        type: 'money',
        toFixed: 2,
      },
      {
        title: '事件',
        key: 'event',
      },
    ],
    pageInfo: {
      currentPage: 1,
      numInPage: 10,
    },
  };
  componentDidMount() {
    this.getTableData();
  }
  getTableData = () => {
    const { dispatch, recordData } = this.props;
    const { pageInfo } = this.state;
    dispatch({
      type: 'nonstandardReportM/getTableDetail',
      payload: {
        queryKey: 'MaatLiabilitySideReport',
        parentInfo: {
          // currentPage: pageInfo.currentPage || 1,
          // numInPage: pageInfo.numInPage || 10,
          id: recordData?.id,
        },
      },
      callback: (msg, res) => {
        if (msg == 'success') {
          this.setState({
            dataSource: res?.dataSource[0]?.children || [],
            pageInfo: res?.pageInfo || {},
          });
        }
      },
    });
  };
  tableOnChange = (pagination) => {
    const { current, pageSize } = pagination;
    const { pageInfo } = this.state;
    this.setState({
      pageInfo: {
        ...pageInfo,
        currentPage: current,
        numInPage: pageSize,
      },
    });
  };
  render() {
    const { dataSource, columns, pageInfo } = this.state;
    return (
      <TableC
        dataSource={dataSource}
        columns={columns}
        hidePage={true}
        scroll={{ y: 350 }}
        loading={this.props.loading}
        // hidePage={pageInfo.total < pageInfo.numInPage}
        // current={pageInfo.currentPage}
        // pageSize={pageInfo.numInPage}
        // onChange={this.tableOnChange}
      />
    );
  }
}
